//
//  HOPPresentationController.swift
//  WB01
//
//  Created by HOP on 16/1/3.
//  Copyright © 2016年 HOP. All rights reserved.
//

import UIKit

// modal出来的控制器关闭的通知
let HOPPresentationControllerDismissNotificaiton = "HOPPresentationControllerDismissNotificaiton"

class HOPPresentationController: UIPresentationController {

    /// 容器视图将要布局
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        // 将背景视图添加到容器视图
        containerView?.addSubview(bkgView)
        bkgView.ff_Fill(containerView!)
        // 将背景视图推到最底部
        containerView?.sendSubviewToBack(bkgView)
        // 获取modal出来的控制器的view
        let modalView = presentedView()
        // 修改modal出来的控制器的view 的大小
        modalView?.frame = CGRect(x: 100, y: 56, width: 200, height: 300)
    }
    /// 背景被点击的方法
    func bkgViewClick () {
    print("需要将modal出来的控制器消失")
    // 获取到modal出来的控制器,并关闭
    presentedViewController.dismissViewControllerAnimated(true, completion: nil)
        // 需要将首页的title按钮转下去,使用通知
        // aName: 通知的名称
        // object: 通知的发送者
        NSNotificationCenter.defaultCenter().postNotificationName(HOPPresentationControllerDismissNotificaiton, object: self)
        
    }
    // MARK: - 懒加载
    /// 灰色的背景
    private lazy var bkgView: UIView = {
    let view = UIView()
    
    // 设置背景颜色
        view.backgroundColor = UIColor(white: 0.3, alpha: 0.2)
        // 添加点击的手势
        let tap = UITapGestureRecognizer(target: self, action: "bkgViewClick")
        view.addGestureRecognizer(tap)
        return view
    }()
    
    
    
    
    
    
    
    
    
    
    
    
    
}
